package com.stm.meet.Controller;

import com.stm.meet.Entitys.CardEntity;
import com.stm.meet.Entitys.MeetEntity;
import com.stm.meet.Repository.CardRepository;
import com.stm.meet.Repository.MeetRepository;
import com.stm.meet.Service.CardService;
import org.hibernate.Hibernate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.jpa.vendor.HibernateJpaSessionFactoryBean;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Controller
@RequestMapping("/meet")
public class MeetController {

    @Autowired
    MeetRepository meetRepository;

    @Autowired
    CardService cardService;

    @RequestMapping("meet_list")
    public String meet_list(Model model){
        List<MeetEntity> meetEntities = (List<MeetEntity>) meetRepository.findAll();
        model.addAttribute("meets",meetEntities);
        return "meet/meet_list";
    }

    @RequestMapping("/info/{meetId}")
    public String meet_info(@PathVariable Integer meetId, Model model){
        List<CardEntity> cardEntities = cardService.getMeetCards(meetId);
        model.addAttribute(meetRepository.findById(meetId));
        model.addAttribute("cards",cardEntities);
        return "meet/meet_info";
    }

}
